home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / catch.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  382b  |  19 lines

  1. #include <setjmp.h>
  2.  
  3. static    int    _catchval;        /* catch/throw return value */
  4.  
  5. int catch(id, fn)            /* execute fn() within a catch frame */
  6.     register jmp_buf *id;
  7.     register int (*fn)();
  8.     {
  9.     return(setjmp(id) ? _catchval : ((*fn)()));
  10.     }
  11.  
  12. throw(id, rv)                /* return rv to the id catch */
  13.     register jmp_buf *id;
  14.     register int rv;
  15.     {
  16.     _catchval = rv;
  17.     longjmp(id, 1);
  18.     }
  19.